﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace Tradex.Connectivity {

    /// <summary>
    /// The ConnectorStatus encodes the current status of a connector. This is one one side a standardized Code
    /// (in the Code field), on the other side a string field that can be used to give a reason for the status -
    /// not usefull for all stati, but some can provide more information on this field.  +
    /// </summary>
    [Serializable()]
    public sealed class ConnectionStatus {

        /// <summary>
        /// Public Constructor taking all values.
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="code"></param>
        /// <param name="message"></param>
        public ConnectionStatus (
            DateTime timestamp,
            ConnectionStatusCode code, string message
        ) {
            Timestamp = timestamp;
            Code = code;
            if (String.IsNullOrWhiteSpace(message)) {
                message = String.Format(CultureInfo.InvariantCulture, "Connection Status {0}", code);
            }
            Message = message;
        }

        /// <summary>
        /// Gets the Timestamp.
        /// </summary>
        public DateTime Timestamp { get; private set; }

        /// <summary>
        /// Gets the connection status code.
        /// </summary>
        public ConnectionStatusCode Code { get; private set; }

        /// <summary>
        /// Gets the message associated with the status.
        /// </summary>
        public string Message { get; private set; }

        /// <inheritdoc />
        public override string ToString() {
            return String.Format(CultureInfo.InvariantCulture, "{0} : {1} / {2}", Timestamp, Code, Message);
        }

    }

}
